//////////////////////////////////////////////////////////////////////////////////////////////
//	File			:	"PauseState.cpp"
//
//	Author			:	Mike Davis, Matt Stover, James Thornton, Keith Webster
//	
//	Project			:	TacWars
//
//	Last Modified	:	11/6/2013
//
//	Purpose			:	
//
//////////////////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "PauseState.h"
#include "OptionsState.h"
#include "InstructionsState.h"
#include "GameplayState.h"
#include "../../SGD Wrappers/CSGD_Direct3D.h"
#include "../../SGD Wrappers/CSGD_DirectInput.h"
#include "../../SGD Wrappers/CSGD_TextureManager.h"
#include "../../SGD Wrappers/CSGD_XAudio2.h"
#include "../../SGD Wrappers/CSGD_MessageSystem.h"
#include "../../SGD Wrappers/CSGD_EventSystem.h"
#include "../../SGD Wrappers/SGD_String.h"
#include "../../SGD Wrappers/SGD_Math.h"
#include "../Game.h"
#include <cassert>

PauseState* PauseState::GetInstance()
{
	static PauseState Instance;

	return &Instance;
}
PauseState::PauseState()
{
	cursor = 0;
	quit = false;
}
PauseState::~PauseState()
{
}
/*virtual*/ void PauseState::Enter()
{
	titleImgID = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/Images/MapStage3.png"));
	player1 = GameplayState::GetInstance()->player1;
}
/*virtual*/ void PauseState::Exit()
{

}
/*virtual*/ bool PauseState::Input()
{
	CSGD_DirectInput* DI = CSGD_DirectInput::GetInstance();

	if(DI->KeyPressed( DIK_DOWN) == true)
	{
		++cursor;
		if(quitBox)
		{
			if(cursor > 1)
				cursor = 1;
		}
		else
		{
			if(cursor > 3)
				cursor = 3;
		}
	}
	else if(DI->KeyPressed(DIK_UP) == true)
	{
		--cursor;

		if(cursor < 0)
			cursor = 0;
	}

	if(DI->KeyPressed(DIK_RETURN) == true && (quitBox == false && endTurnBox == false))
	{
		switch(cursor)
		{
		case 0:
			{
				cursor = 0;
				Game::GetInstance()->PushState(OptionsState::GetInstance());			
			}
			break;
		case 1:
			{
				cursor = 0;
				Game::GetInstance()->PushState(InstructionsState::GetInstance());
			}
			break;
		case 2:
			{
				endTurnBox = true;
				cursor = 0;
				//end turn
			}
			break;
		case 3:
			{
				quitBox = true;
				cursor = 0;
				//surrender
			}
			break;
		}
	}
	else if(DI->KeyPressed(DIK_RETURN) == true && quitBox == true)
	{
		switch(cursor)
		{
		case 0:
			{
				Game::GetInstance()->PopState();
				Game::GetInstance()->PopState();
				Game::GetInstance()->PopState();
				Game::GetInstance()->PopState();
				Game::GetInstance()->PopState();
				quitBox = false;
				return true;
			}
			break;
		case 1:
			{
				
				cursor = 0;
				quitBox = false;
			}
			break;
		}
	}
	else if(DI->KeyPressed(DIK_RETURN) == true && endTurnBox == true)
	{
		switch(cursor)
		{
		case 0:
			{
				player1->AvailableUnits.clear(); 
				endTurnBox = false;
				Game::GetInstance()->PopState();
				return true;
			}
			break;
		case 1:
			{
				endTurnBox = false;
				cursor = 0;
			}
			break;
		}
	}

	if(DI->KeyPressed(DIK_ESCAPE) == true)
	{
		if(endTurnBox == true)
		{
			endTurnBox = false;
		}
		else if(quitBox == true)
		{
			quitBox = false;
		}
		else
		Game::GetInstance()->PopState();
	}
	return true;
}
/*virtual*/ void PauseState::Update( float fElapsedTime )
{

}
/*virtual*/ void PauseState::Render()
{
	BitmapFont* Font = Game::GetInstance()->GetFont();
	CSGD_TextureManager::GetInstance()->Draw(titleImgID, 0, 0, 1.0f, 1.0f);

	Font->Draw( _T("GAME PAUSED"), 
		(int)((640 - (4*32*2.0f)) / 2), 
		100, 2.0f, D3DCOLOR_ARGB(255, 255, 255, 255) );


	Font->Draw( _T("OPTIONS"), (500 - (4*32)) / 2, 300, 1.0f, D3DCOLOR_ARGB(255, 255, 255, 255) );
	Font->Draw( _T("CONTROLS"), (500 - (4*32)) / 2, 350, 1.0f, D3DCOLOR_ARGB(255,255,255,255));
	Font->Draw( _T("END TURN"), (500 - (4*32)) / 2, 400, 1.0f, D3DCOLOR_ARGB(255,255,255,255));
	Font->Draw( _T("SURRENDER"), (500 - (4*32)) / 2, 450, 1.0f, D3DCOLOR_ARGB(255,255,255,255));

	if(quitBox == true)
	{
		CSGD_TextureManager::GetInstance()->Draw(titleImgID, 0, 0);
		Font->Draw( _T("ADMIT DEFEAT?"), (500 - (4*32)) / 2, 250, 1.0f, D3DCOLOR_ARGB(255,255,255,255));
		Font->Draw( _T("YES"), (500 - (4*32)) / 2, 300, 1.0f, D3DCOLOR_ARGB(255,255,255,255));
		Font->Draw( _T("NO"), (500 - (4*32)) / 2, 350, 1.0f, D3DCOLOR_ARGB(255,255,255,255));
	}
	if(endTurnBox == true)
	{
		CSGD_TextureManager::GetInstance()->Draw(titleImgID, 0, 0);
		Font->Draw( _T("END YOUR TURN?"), (500 - (4*32)) / 2, 250, 1.0f, D3DCOLOR_ARGB(255,255,255,255));
		Font->Draw( _T("YES"), (500 - (4*32)) / 2, 300, 1.0f, D3DCOLOR_ARGB(255,255,255,255));
		Font->Draw( _T("NO"), (500 - (4*32)) / 2, 350, 1.0f, D3DCOLOR_ARGB(255,255,255,255));
	}

	Font->Draw( _T("(     \t\t)"), (500 - (7*32)) / 2, 300 + (cursor * 50), 1.0f, D3DCOLOR_ARGB(255, 255, 255, 255) );

}
void PauseState::SaveSoundInfo() const
{
	//ofstream fout("soundInfo.txt");
	//if(fout.is_open())
	//{
	//	fout << musVol << "\n" << sfxVol;
	//	fout.close();
	//}
	//fout.close();
}
void PauseState::LoadSoundInfo()
{
	//ifstream fin("soundInfo.txt");
	//if(fin.is_open())
	//{
	//	fin >> musVol >> sfxVol;
	//}
	//fin.close();

	//CSGD_XAudio2::GetInstance()->MusicSetMasterVolume(musVol/100);
	//CSGD_XAudio2::GetInstance()->SFXSetMasterVolume(sfxVol/100);
}